package cn.huiyunche.admin.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.huiyunche.base.service.vo.PageVo;

/**
 * main 控制器 
 * @author hdy [Tuffy]
 */
@Controller
@RequestMapping("/data")
public class DataController {

	@Autowired
	private JdbcTemplate jdbcTemplate = null;
	
	/**
	 * 车型列表
	 * @return 车型列表
	 */
	@RequestMapping(value = "/brand", method = RequestMethod.GET)
	@ResponseBody
	public Map<String, Object> vehicleList(PageVo page) {
		List<Map<String, Object>> list = this.getJdbcTemplate().queryForList("select * from vehicle_brand limit " + page.getStartIndex()
			+ ", " + page.getPageSize());
		Map<String, Object> result = new HashMap<>();
		result.put("data", list);
		page.setTotalRecord(this.getJdbcTemplate().queryForObject("select count(id) from vehicle_brand", Integer.class));
		result.put("page", page);
		return result;
	}
	
	private JdbcTemplate getJdbcTemplate() {
		return this.jdbcTemplate;
	}
}
